package com.tledu.day62springboot.core;

import com.tledu.day62springboot.entity.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * @author cyrus
 */
@RestControllerAdvice
public class GlobalControllerAdvice {

    @ExceptionHandler(value = Exception.class)
    public Result<Void> handleException(Exception e) {
        return Result.error(500, e.getMessage());
    }

    @ExceptionHandler(value = CustomException.class)
    public Result<Void> handleCustomException(CustomException e) {
        return Result.error(e.getCode(), e.getMessage());
    }
}
